<?php
/**
 *  支付适配器
 *
 * @date    2018-07-26 09:39:44
 * @version $Id$
 */

namespace App\Commons\Services\Payment;

final class PaymentAdapter
{
    private static $instances = [];
    /**
     * 获取支付适配器
     * 注：可以考虑用服务容器的方式
     * @param  string $type 支付类型：alipay、wechat
     * @return [type]       [description]
     */
    public static function getAdapter(string $type)
    {
        $class_name = 'App\\Commons\\Services\\Payment\\'. ucfirst($type).'Adapter';
        throw_on(!class_exists($class_name), '支付方式不支持：'. $type);
        if (!isset(self::$instances[$type])) {
            self::$instances[$type] = new $class_name;
        }

        return self::$instances[$type];
    }
}
